//引入重置样式
require('../css/commCss/normalize.css')
//引入重置扩展样式
require('../css/commCss/reset.css')
//引入公共样式
require('../css/commCss/property.css')
//引入公共扩展样式
require('../css/commCss/basic.css')

//引入字体图标样式
require('../lib/font_3139541_zokbtoztf/iconfont.css')

//引入当前页面样式
require('../css/home.less')


//引入swiper样式
require('../lib/swiper/swiper插件css样式引入.css')
//引入swiper的js
const Swiper = require('../lib/swiper/swiper轮播图插件js')

//引入axios
const axios = require('axios')

//导入weui
require("weui")
const weui = require("weui.js")

//导入util
const util = require('../lib/util')

//文档加载事件
document.addEventListener('DOMContentLoaded', function () {
  /**
   * 0.获取元素
   */
  const rank = document.querySelector('#rank')
  const punchDay = document.querySelector('#punchDay')
  const todayPunch = document.querySelector('#todayPunch')
  const badge = document.querySelector('#badge')

  /**
 * 1.底部导航
 */
  util.fixBottomNav("home");

  //初始化配置swiper
  function setswiper() {
    var mySwiper = new Swiper('.swiper', {
      loop: true, // 循环模式选项
      autoplay: {
        delay: 1000, //延迟时间
        disableOnInteraction: false  //是否禁止自动滚动
      },
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
      },

    })
  }
  setswiper()

  /**
   * 2.首页数据渲染
   */

  axios.get('http://139.9.177.51:8099/headPageInfo', {
    params: {
      userId: localStorage.getItem('userId')
    }
  }).then(function (res) {

    if (res.data.status === 0) {
      rank.textContent = res.data.data.rank
      punchDay.textContent = res.data.data.punchIn
      badge.textContent = res.data.data.insigniaNum

      //rank.textContent = res.data.data.rank
      res.data.data.isPunch === 'true' ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
    }
  })


  /**
   * 3.今日打卡
   */

  todayPunch.addEventListener('click', function () {
    axios.get('http://139.9.177.51:8099/clockIn', {
      params: {
        userId: localStorage.getItem('userId')
      }
    }).then(function (res) {
      if (res.data.status === 0) {//代表进行点击事件打卡发送请求,状态码=0就是打卡成功
        punchDay.textContent++//自加,就是在每次已打卡后再加自加1
        todayPunch.textContent = '已打卡'
        weui.toast('打卡成功', 1000)
      } else {
        weui.toast('已打卡', 1000)//1s后跳出轻提示
      };
    })
  })

  /* 
    4:点击home页面的运动数据,跳转到对应的运动数据页面
  */
  document.querySelector('#contenttwoLt').addEventListener('click', function () {
    // console.log(1);
    location.href = 'Movementdata.html'
  })

  /* 
  5.点击todayPunch进入我的徽章页面
  */
  document.querySelector('#myBadge').addEventListener('click', function () {
    location.href = 'Mybadge.html'
  })

})